package TestCases;

import java.util.ArrayList;
import pos.control.TaxControl;
import pos.entity.Order;
import pos.entity.PriceAdjustment;
import pos.entity.PurchasedItem;

/**
 *
 * @author Justin Hume
 */
public class UnitTestOracle_OrdersAndPItems {

    //Oracle CONSTANTS

    //Purchased item 1
    private static final double PITEM1_BASEPRICE = 500;

    private static final double PITEM1_DISCOUNTS = 150;
    private static final double PITEM1_TAXES = 49;
    private static final double PITEM1_TOTALPRICE = 399;

    //Purchased item 2
    private static final double PITEM2_BASEPRICE = 1000;

    private static final double PITEM2_DISCOUNTS = 125;
    private static final double PITEM2_TAXES = 122.5;
    private static final double PITEM2_TOTALPRICE = 997.5;

    //Order
    private static final double ORDER_BASEPRICE = 1500;
    private static final double ORDER_DISCOUNTS = 275;
    private static final double ORDER_TAXES = 171.5;
    private static final double ORDER_TOTALPRICE = 1396.5;

    //Oracle order and purchased items
    private Order _oracleOrder;
    private ArrayList<PurchasedItem> _oraclePurchasedItemList;

    //ORACLE CONSTRUCTOR
    public UnitTestOracle_OrdersAndPItems() {

        //Add purchased item 1
        PurchasedItem pItem1 = new PurchasedItem();

        //Set required information
        pItem1.setPurchaseItemId(1);
        pItem1.setBasePrice(500);
        pItem1.setName("Purchased Item 1");

            //Add price adjustment 1
            PriceAdjustment pAdj1 = new PriceAdjustment(1, 50, 1,
                PriceAdjustment.PriceAdjustmentType.MISC,
                "Adj: 50",
                1, -1);

            //Add price adjustment 2
            PriceAdjustment pAdj2 = new PriceAdjustment(1, 100, 1,
                PriceAdjustment.PriceAdjustmentType.SPECIAL,
                "Adj: 100",
                1, -1);

            //Add price adjustments to purchased item 1
            pItem1.setPriceAdjustments(pAdj1);
            pItem1.setPriceAdjustments(pAdj2);


        //Add purchased item 1
        PurchasedItem pItem2 = new PurchasedItem();

        //Set required information
        pItem2.setPurchaseItemId(2);
        pItem2.setBasePrice(1000);
        pItem2.setName("Purchased Item 2");

            //Add price adjustment 1
            PriceAdjustment pAdj11 = new PriceAdjustment(1, 125, 1,
                PriceAdjustment.PriceAdjustmentType.GRATUITY,
                "Adj: 125",
                1, -1);

            pItem2.setPriceAdjustments(pAdj11);

        //Create purchased items list
        ArrayList<PurchasedItem> pItemList = new ArrayList<PurchasedItem>();

        //Add purchased items to list
        pItemList.add(pItem1);
        pItemList.add(pItem2);

        //Add taxes to purchased item list
        TaxControl taxCtrl = new TaxControl();
        taxCtrl.addPurchasedItemTax(pItem1);
        taxCtrl.addPurchasedItemTax(pItem2);

        //Instantiate order
        Order order1 = new Order();

        //Set order fields
        order1.setOrderId(1);
        order1.setPurchasedItems(pItemList);

        //Set fields for oracle
        _oracleOrder = order1;
        _oraclePurchasedItemList = pItemList;
    }

    //PUBLIC PROPERTIES
    public Order getOracleOrder() {

        return _oracleOrder;
    }

    public ArrayList<PurchasedItem> getOraclePItemList() {

        return _oraclePurchasedItemList;
    }
    
    //Oracle validation methods

    //Validate the order
    public boolean orderIsValid(Order orderToValidate) {

        //Test the four order price attributes, in sequence.
        //The test fails if any of them are not equal to the
        //oracle values 
        boolean testPassed = true;

        if (orderToValidate.getOrderTotalBasePrice() != ORDER_BASEPRICE) {

            System.out.println("FAIL: order BASE PRICE");
            testPassed = false;
        }

        if (orderToValidate.getOrderTotalAdjustedAmount() != ORDER_DISCOUNTS) {

            System.out.println("FAIL: order DISCOUNTS");
            testPassed = false;
        }
        
        if (orderToValidate.getOrderTotalTaxes() != ORDER_TAXES) {

            System.out.println("FAIL: order TAXES");
            testPassed = false;
        }

        if (orderToValidate.getOrderTotalPrice() != ORDER_TOTALPRICE) {

            System.out.println("FAIL: order TOTAL PRICE");
            testPassed = false;
        }

        //return the test result
        return testPassed;
    }

    //Validate the purchased items
    public boolean purchasedItemsAreValid(ArrayList<PurchasedItem> purchasedItemList) {

        //Test the four order price attributes, in sequence.
        //The test fails if any of them are not equal to the
        //oracle values
        boolean testPassed = true;

        //Purchased item 1
        if (purchasedItemList.get(0).getBasePrice() != PITEM1_BASEPRICE) {

            System.out.println("FAIL: pItem1 BASE PRICE");
            testPassed = false;
        }

        if (purchasedItemList.get(0).getPriceAdjustedAmount() != PITEM1_DISCOUNTS) {

            System.out.println("FAIL: pItem1 DISCOUNTS");
            testPassed = false;
        }

        if (purchasedItemList.get(0).getTotalTaxes() != PITEM1_TAXES) {

            System.out.println("FAIL: pItem1 TAXES");
            testPassed = false;
        }

        if (purchasedItemList.get(0).getTotalPrice() != PITEM1_TOTALPRICE) {

            System.out.println("FAIL: pItem1 TOTAL PRICE");
            testPassed = false;
        }

        //Check that four price adjustments still exist
        if (purchasedItemList.get(0).getPriceAdjustments().size() != 4) {

            System.out.println("FAIL: pItem1 WRONG # ADJUSTMENTS");
            testPassed = false;
        }


        //Purchased item 2
        if (purchasedItemList.get(1).getBasePrice() != PITEM2_BASEPRICE) {

            System.out.println("FAIL: pItem2 BASE PRICE");
            testPassed = false;
        }

        if (purchasedItemList.get(1).getPriceAdjustedAmount() != PITEM2_DISCOUNTS) {

            System.out.println("FAIL: pItem2 DISCOUNTS");
            testPassed = false;
        }

        if (purchasedItemList.get(1).getTotalTaxes() != PITEM2_TAXES) {

            System.out.println("FAIL: pItem2 TAXES");
            testPassed = false;
        }

        if (purchasedItemList.get(1).getTotalPrice() != PITEM2_TOTALPRICE) {

            System.out.println("FAIL: pItem2 TOTAL PRICE");
            testPassed = false;
        }

        //Check that four price adjustments still exist
        if (purchasedItemList.get(1).getPriceAdjustments().size() != 3) {

            System.out.println("FAIL: pItem2 WRONG # ADJUSTMENTS");
            testPassed = false;
        }

        //return the test result
        return testPassed;
    }
}
